class Button {

  Sprite defaultSprite_;
  Sprite pressedSprite_;
  vec4 centre_;
  vec4 halfExtents_;

  bool pressed_;
  bool visible_;
  bool engaged_;

public:
  Button() {}

  void init(int image, int pressedImage, vec4 centre, vec4 halfExtents) {
    defaultSprite_ = Sprite(image, halfExtents);
    pressedSprite_ = Sprite(pressedImage, halfExtents);
    centre_ = centre;
    halfExtents_ = halfExtents;
    pressed_ = false;
    visible_ = false;
    engaged_ = false;
  }

  void setPressed(bool p) {pressed_ = p;}

  bool isPressed() {return pressed_;}

  void draw(shader &shader, texture* tex, mat4 &modelToProjection) {

    if (pressed_) {
      pressedSprite_.draw(centre_, true, shader, tex, modelToProjection);
    }
    else {
      defaultSprite_.draw(centre_, true, shader, tex, modelToProjection);
    }
  }

  void setVisible(bool v) {visible_ = v;}
  void setEngaged(bool e) {engaged_ = e;}

  bool isEngaged() {return engaged_;}
  bool isVisible() {return visible_;}
  vec4 getCentre() {return centre_;}
  vec4 getHalfExtents() {return halfExtents_;}

  bool isInside(int x, int y) {
    bool inside = false;

    float left = centre_[0] - halfExtents_[0];
    float right = centre_[0] + halfExtents_[0];
    float top = centre_[1] + halfExtents_[1];
    float bottom = centre_[1] - halfExtents_[1];

    if (x > left && x < right) {
      if (y > bottom && y < top) {
        inside = true;
      }
    }
    return inside;
  }
};
